package com.MSB.LinkedList;

import java.util.Stack;

/**
 * 使用两个栈实现队列
 */
public class StacksImpQueue {
    public Stack<Integer> stackPush = new Stack<>();
    public Stack<Integer> stackPop = new Stack<>();

    /**
     * 只有当pop栈为空，才可以倒数据进pop栈
     * 要保证push栈的数据全部导入pop栈
     */
    private void pushToPop(){
        if (stackPop.empty()){
            while (!stackPush.empty()){
                stackPop.push((stackPush.pop()));
            }
        }
    }
    public void add(int pushInt){
        stackPush.push(pushInt);

    }
    public int poll(){
        pushToPop();
        if (stackPop.empty()){
            throw new RuntimeException("Queue is empty!");
        }
        return stackPop.pop();
    }

}
